package conf

import "fmt"

type Conf struct {
	Server    `yaml:"Server"`
	LogZap    `yaml:"LogZap"`
	LogFile   `yaml:"LogFile"`
	RedisConf `yaml:"Redis"`
	MysqlConf `yaml:"DB"`
	GormConf  `yaml:"Gorm"`
	Mode      string `yaml:"Mode"`
}
type Server struct {
	Port int `yaml:"Port"`
}
type LogZap struct {
	Level  int `yaml:"Level"`
	Output int `yaml:"Output"`
}
type LogFile struct {
	Filename   string `yaml:"FileName"`
	MaxSize    int    `yaml:"MaxSize"`
	MaxBackups int    `yaml:"MaxBackups"`
	MaxAge     int    `yaml:"MaxAge"`
	Compress   bool   `yaml:"Compress"`
}

type RedisConf struct {
	Enable string `yaml:"Enable"`
	Host   string `yaml:"Host"`
	Port   string `yaml:"Port"`
}

type MysqlConf struct {
	Host       string `yaml:"Host"`
	Port       int    `yaml:"Port"`
	User       string `yaml:"User"`
	Password   string `yaml:"Password"`
	DBName     string `yaml:"DBName"`
	Parameters string `yaml:"Parameters"`
}

func (d *MysqlConf) DSN() string {
	return fmt.Sprintf(
		"%s:%s@tcp(%s:%d)/%s?%s",
		d.User,
		d.Password,
		d.Host,
		d.Port,
		d.DBName,
		d.Parameters,
	)
}

type GormConf struct {
	Debug        string `yaml:"Debug"`
	MaxLifetime  int    `yaml:"MaxLifetime"`
	MaxOpenConns int    `yaml:"MaxOpenConns"`
	MaxIdleConns int    `yaml:"MaxIdleConns"`
}
